﻿<%@ Page Language="C#" MasterPageFile="../main.master" Inherits="VioletDevelopmentLaboratory.Net.Web.Configuration.VWebConfigManagerPage" %>

<script runat="server">
	protected void ConnectionStringsGridView_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
	{
		ConnectionStringsDetailsView.ChangeMode(DetailsViewMode.ReadOnly);
	}

	protected void ConnectionStringsDetailsView_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
	{
		ShowAlert_DetailsView_ItemInserted(e);

		ConnectionStringsGridView.SelectedIndex = -1;
		ConnectionStringsGridView.DataBind();
	}

	protected void ConnectionStringsDetailsView_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
	{
		ShowAlert_DetailsView_ItemUpdated(e);

		ConnectionStringsGridView.SelectedIndex = -1;
		ConnectionStringsGridView.DataBind();
	}

	protected void ConnectionStringsDetailsView_ItemDeleted(object sender, DetailsViewDeletedEventArgs e)
	{
		ShowAlert_DetailsView_ItemDeleted(e);

		ConnectionStringsDetailsView.ChangeMode(DetailsViewMode.Insert);

		ConnectionStringsGridView.SelectedIndex = -1;
		ConnectionStringsGridView.DataBind();
	}
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="BodyContentPlaceHolder" runat="server">

	<h2>ConnectionStrings</h2>

	<div>
		<asp:ObjectDataSource ID="ConnectionStringsDetailsViewDataSource" runat="server" 
			DeleteMethod="Remove" InsertMethod="Add" SelectMethod="GetSettings" 
			TypeName="VioletDevelopmentLaboratory.Net.Web.Configuration.ConnectionStringsSectionManager" 
			UpdateMethod="Modify">
			<DeleteParameters>
				<asp:Parameter Name="name" Type="String" />
			</DeleteParameters>
			<UpdateParameters>
				<asp:Parameter Name="name" Type="String" />
				<asp:Parameter Name="connectionString" Type="String" />
				<asp:Parameter Name="providerName" Type="String" />
			</UpdateParameters>
			<SelectParameters>
				<asp:ControlParameter ControlID="ConnectionStringsGridView" Name="key" 
					PropertyName="SelectedValue" Type="String" />
			</SelectParameters>
			<InsertParameters>
				<asp:Parameter Name="name" Type="String" />
				<asp:Parameter Name="connectionString" Type="String" />
				<asp:Parameter Name="providerName" Type="String" />
			</InsertParameters>
		</asp:ObjectDataSource>
		<asp:ObjectDataSource ID="ConnectionStringsGridViewDataSource" runat="server" 
			SelectMethod="GetSettingsCollection" 
			
			TypeName="VioletDevelopmentLaboratory.Net.Web.Configuration.ConnectionStringsSectionManager">
		</asp:ObjectDataSource>
		<fieldset>
			<asp:DetailsView ID="ConnectionStringsDetailsView" runat="server" 
				AutoGenerateRows="False" CellPadding="5" 
				DataSourceID="ConnectionStringsDetailsViewDataSource" 
				oniteminserted="ConnectionStringsDetailsView_ItemInserted" 
				onitemupdated="ConnectionStringsDetailsView_ItemUpdated" 
				onitemdeleted="ConnectionStringsDetailsView_ItemDeleted" DataKeyNames="Name" 
				DefaultMode="Insert" >
				<Fields>
					<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" 
						SortExpression="Name" />
					<asp:BoundField DataField="ConnectionString" HeaderText="ConnectionString" 
						SortExpression="ConnectionString" />
					<asp:BoundField DataField="ProviderName" HeaderText="ProviderName" 
						SortExpression="ProviderName" />
					<asp:CommandField ButtonType="Button" ShowDeleteButton="True" 
						ShowEditButton="True" ShowInsertButton="True" />
				</Fields>
			</asp:DetailsView>
			<asp:GridView ID="ConnectionStringsGridView" runat="server" AutoGenerateColumns="False" CellPadding="5"
				DataKeyNames="Name" DataSourceID="ConnectionStringsGridViewDataSource"
				onselectedindexchanging="ConnectionStringsGridView_SelectedIndexChanging">
				<Columns>
					<asp:CommandField ShowSelectButton="True" />
					<asp:BoundField DataField="Name" HeaderText="Name" />
					<asp:BoundField DataField="ConnectionString" HeaderText="ConnectionString" />
					<asp:BoundField DataField="ProviderName" HeaderText="ProviderName" />
				</Columns>
				<SelectedRowStyle BackColor="SkyBlue" />
			</asp:GridView>
		</fieldset>
	</div>
</asp:Content>